<template id="searchBar">
  <div class="content">
    <div class="seachSelect">
      <div class="currentSelect" @click="openOptions">
        <img :src="selectIconLeft" class="selectIconLeft" />
        <p class="currentName">{{ selectOptions.current.name }}</p>
        <img :src="dropdownIcon" class="dropdownIcon" />
      </div>
      <div
        class="selectOptions"
        :class="[
          { isShow: selectOptions.isShow && !isInit },
          { isClose: !selectOptions.isShow && !isInit },
        ]"
      >
        <div
          class="selectList"
          v-for="item in selectOptions.list"
          :key="item.value"
          @click="changeValue(item)"
        >
          <p :class="{ isChose: selectOptions.current.value == item.value }">
            {{ item.name }}
          </p>
          <img
            :src="choseIcon"
            class="choseIcon"
            v-if="selectOptions.current.value == item.value"
          />
        </div>
      </div>
    </div>
    <div class="searchText">
      <input
        type="text"
        v-model="selectOptions.inputValue"
        placeholder="请输入搜素内容"
      />
    </div>
    <div class="searchBtn" @click="search">
      查找
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  name: "",
  props: {
    selectOptions: {
      type: Object,
    },
  },
  data() {
    return {
      selectIconLeft: require("@/assets/images/mail/types.png"),
      dropdownIcon: require("@/assets/images/mail/dropdown.png"),
      choseIcon: require("@/assets/images/mail/chose.png"),
      isInit: true,
    };
  },
  computed: {},
  methods: {
    //打开选项框
    openOptions() {
      this.isInit = false;
      this.$emit("open", true);
    },

    //更改选项
    changeValue(item) {
      this.$emit("change", item);
    },

    //搜索
    search() {
      this.$emit("search");
    },
  },
  mounted() {},
};
</script>

<style lang="less" scoped>
.content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-right: 50px;
  .seachSelect {
    position: relative;
    .currentSelect {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .selectIconLeft {
        width: 12px;
        height: 12px;
      }
      .currentName {
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #ffffff;
        margin: 0 6px;
      }

      .dropdownIcon {
        width: 9px;
        height: 5px;
      }
    }
    .selectOptions {
      position: absolute;
      top: 22px;
      right: 0;
      z-index: 9;
      width: 138px;
      background: #1e2020;
      box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
      border-radius: 4px;
      padding: 10px 0;
      visibility: hidden;
      .selectList {
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px 10px;
        cursor: pointer;

        p {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #8e8f8f;
        }

        .choseIcon {
          width: 14px;
          height: 10px;
        }

        .isChose {
          color: #01f5ab;
        }
      }
      .selectList:hover {
        background: rgba(255, 255, 255, 0.03);
      }

      .selectList:first-child {
        margin-top: 0;
      }
    }
    .isShow {
      -webkit-animation: fade-in 0.3s cubic-bezier(0.39, 0.575, 0.565, 1) both;
      animation: fade-in 0.3s cubic-bezier(0.39, 0.575, 0.565, 1) both;

      @-webkit-keyframes fade-in {
        0% {
          opacity: 0;
        }

        100% {
          opacity: 1;
        }
      }

      @keyframes fade-in {
        0% {
          opacity: 0;
        }

        100% {
          opacity: 1;
          visibility: visible;
        }
      }
    }

    .isClose {
      -webkit-animation: fade-out 0.3s ease-out both;
      animation: fade-out 0.3s ease-out both;

      @-webkit-keyframes fade-out {
        0% {
          opacity: 1;
        }

        100% {
          opacity: 0;
        }
      }

      @keyframes fade-out {
        0% {
          opacity: 1;
        }

        100% {
          opacity: 0;
          visibility: hidden;
        }
      }
    }
  }
  .searchText {
    margin: 0 20px;
    input {
      width: 180px;
      height: 32px;
      background: #343636;
      border-radius: 16px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
      line-height: 14px;
      border: none;
      padding-left: 39px;
      padding-right: 10px;
    }
    input::-webkit-input-placeholder {
      /* WebKit browsers 适配谷歌 */
      color: rgba(255, 255, 255, 0.5) !important;
    }

    input:-moz-placeholder {
      /* Mozilla Firefox 4 to 18 适配火狐 */
      color: rgba(255, 255, 255, 0.5) !important;
    }

    input::-moz-placeholder {
      /* Mozilla Firefox 19+ 适配火狐 */
      color: rgba(255, 255, 255, 0.5) !important;
    }

    input:-ms-input-placeholder {
      /* Internet Explorer 10+  适配ie*/
      color: rgba(255, 255, 255, 0.5) !important;
    }
  }
  .searchBtn {
    display: flex;
    justify-content: center;
    align-items: center;
    background: none;
    border: none;
    width: 60px;
    height: 30px;
    border-radius: 5px;
    border: 1px solid #00ffb0;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #00ffb0;
    line-height: 14px;
    word-break: keep-all;
    cursor: pointer;
  }
}
</style>
